home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Commodore Free 23
/
Commodore_Free_Issue_23_2008_Commodore_Computer_Club.d64
/
t.b guide 8.1
< prev
next >
Wrap
Text File
|
2023-02-26
|
12KB
|
394 lines
u
In the Beginning Chapter 8 Section 1
-------------------------
\Lord Ronin from Q-Link\
Personal part here, I did say before
that this is a personal look on the
C=. One of the first programmes that I
ever typed in was a game very similar
to this upcoming guessing game. What I
did was mess about with the colours
and the word print statements.
According to some of the big time
programmers on the different Internet
C= lists. that makes me a none
programmer. Agree or not, the point of
this story is that you should feel
free to play with the programme, you
are not going to hurt the C=.
1 REM NUMBER GUESSING GAME
2 ?"(SHIFTED CLEAR HOME)"
5 INPUT"ENTER UPPERLIMIT FOR GUESS";LI
10 NM=INT(LI*RND(1))+1
15 CN=0
20 ?"I'VE GOT THE NUMBER.":?
30 ?"WHAT'S YOUR GUESS";GU
35 CN=CN+1
40 IFGU>NMTHEN?"MY NUMBER IS
LOWER":?:GOTO30
50 IFGU<NMTHEN?"MY NUNMBER IS
HIGHER:?:GOTO30
60 ?"GREAT! YOU GOT MY NUMBER"
65 ?"IN ONLY ";CN;"GUESSES.":?
70 ?"DO YOU WANT TO TRY ANOTHER(Y/N)";
80 GETAN$:IFAN$=""THEN80
90 IFAN$="Y"THEN2
100 IFAN$<>"N"THEN70
110 END
Oh wow man that is a mess of
meaningless drenn; lets try to take it
apart. First thought some information
about the use of spaces. The Commodore
book shows the listing with spaces
separating the individual parts or
commands, Spaces reduce the amount of
commands that can be entered on each
line. Spaces also take up a byte or so
in memory use, so no spaces help
tighten the programme, and make it
much harder for you and me to see the
different parts. So lets go line by
line, I'll suspect that you have typed
the program in and run it already.
Line 1
the rem statement, This tells you what
the programme is about for this
listing, rem is REMARK and can be
anything you like the programme just
ignores the command. Here they are
using Rem to show the title of the
programme. I'm a lazy person and so
don't do it myself, although it is
good practice.
Line 2
The print command with the shifted
clear home, the screen is clean up and
putts the cursor at the top left.
Line 5
That input statement we covered a
little bit earlier, you can see what
will be written to screen by the text
in quotes. Just like a regular print
statement. Here what ever you type in
will become the variable li. That li
variable pops up again in line 10.
Line 10
The random number generator, not much
different to our previous dealing with
this command; Here we don't have a
specific number locked into a formula.
We are using the 0 variable LI.
Line 20
The print statement that just writes
to the screen it is ready.
Line 30
Input line for you put enter your
number, this becomes the variable gu.
Line 35
adds one to the count.
Line 40
Takes your number as the variable gu,
compares it to the generated number
and sees if it is greater than the
generated number. Programme commands
to do that read if gu > than nm. Short
and easy for the computer but a whole
new language for us. Second part of
the line is the print statement to
tell you that the number is lower than
your guess.
Line 50
This is the reverse of line 40, both
lines end with the programme taking
you back to line 30, where you are
doing the guess and the count of your
guesses is being recorded.
Line 60
This is the line that gets to some
people it looks wrong to them, I have
been over this line many a times with
users in our group. There are only
three things that can happen, your
number is higher or lower or right on
Ie you guessed correctly. Line 40 & 50
cover the high and low part. Since the
computer goes from the lowest line
number to the highest <unless
something moves it elsewhere> If line
40 isn' true, then the program goes to
line 50, which if it isn't true, Well
there is only one other option, that
is you guessed correctly. That is why
this is after the other two
possibilities.
Line 65
Prints out text and as you see there
is a break in the text where between
the ; symbols there is the cn
variable. This variable will be
printed out as the number on the
screen. Then more text appears, OK
that print thing after the : symbol
will do that drop down a line down
again trick.
Line 70
Goes with the part to play again, Here
the (y/n) is part of the print
statement. As you see in lines 80-100
where the prg is checking to see your
keypress from the KB. Line 80 keeps
the programme stuck at that point,
until there is a keypress, Line 90
gets the y from the keyboard and
starts the game over again. Line 100
is expecting the n and if it doesn't
get it, remember that if a y was typed
we won't be at line 100. So if the
input wasn't an n the Programme goes
back to line 70. Putting up the text
another try. This is an error trap,
just making certain that the user has
only the two listed options.
Go ahead and play with the text line
numbers that you insert. Mess about
with screen, border and even the
different text colours. We have a bit
more on this one. And I did say that I
would cover that weird part.
Well it is easier to see the programme
functions as you play with it and then
alter it a bit. However the book wants
you to figure out how to set up a
lower limit, now you can fight with
this idea for a while, bash your head
against the wall and the keyboard,
then send me and e-mail that says I
have done this better than the manual.
<Stand by, having a laughing fit at
that idea> Well that is the feeling
every student in the user group had at
this part, You see they want you to go
back in the book to that weird line,
the line that makes no sense as it is
written.
Read in the book on page 50 as
follows, and on one line.
NM=INT(LOWERLIMIT+
(UPPER-LOWER+1)*RND(1))
OK we can see from the guessing game
that nm would be the variable, the
rest almost appears to make sense.
You will need to recreate a new input
line, where you ask for the lower
limit; I made this the variable lo. So
now you need to write that random
number generator line, something like
this should work.
NM=INT(LO+(LI-LO+1)*RND(1))
A bit more understanding, but maybe if
I substitute the variables into a set
of numbers, you can see it better, I
had to do that for members of the
group.
NM=INT(50(100-50+1)*RND(1))
If you want to see how this works out
for you, there is something I haven't
really said yet. You can print out the
value of nm, all you need to do is
type on the screen just after you have
written the above line press return
and dont put this in the programme you
are working upon.
?NM <press RETURN>
The value will be printed right
underneath the nm part you typed,
right cursor up to the random
generator line, press return. Go to
back to the ? nm line and then press
return key, now you get a different
number each time.Right back to the
guessing game programme if you didn't
do it already well it is too late to
save the programme. List it and see if
it is still there and if so what was
damaged, Yeah I am tricking you. <VBG>
I'll let you figure out where to place
the input line for the lower limit, as
to where the random number generator
line should be. <SEG> Next type
programme is small and I would not
include it at this time but there is a
trick on the user from the user book,
and I want you to work with colour,
the Book read as follows.
5 ? "CARE TO TRY YOUR LUCK?"
10 ?"RED DICE =";INT(6*RND(1))+1
20 ?"WHITE DICE =";INT(6*RND(1))+1
30 ?"HIT SPACE BAR FOR ANOTHER ROLL":?
40 GETA$:IFA$=""THEN40
50 IFA$=CHR$(32)THEN10
Right, save for the tightening of the
programme lines, this is the way that
the book has you type it in, So where
are the tricks to you? Well first one
that I saw was using the plural of
DICE rather than the singular term
which is DIE. You know one DIE two
DICE, But that probably isn't the
first thing that caught your eye. Line
5 is in lower case, that isn't my
programme style or the way I typed out
the line, that is the way it is
written in the book on page 52. I'm
guessing that they wanted to
automatically see it and do the C= and
shift key press to move to lower case,
but type the other lines in upper
case. Did you notice that you aren't
told to "new" the programme? If you
didn't then the programme we typed in
before would still be in the computer
memory, makes the programme run crazy,
that is if it will run at all.
What I want you to do is make the
screen black and the border black,
also I want you to make the words RED
DICE <or for the purist DIE> as red
and the words WHITE DICE as white,
tough assignment isn't it? Well yes it
is for those in the group that didn't
take notes, you have this drivel in a
form that you can use to read back a
bit. on disk or on paper. However that
was a few lessons ago and I will be
here to lend a hand.
Written in lower case it looks like.
pO53280,0:pO53281,0
These 2 command make the screen and
the border go black. What you need to
do is think where in the programme the
commands should be placed, Hint, the
programme thinks in a straight line,
from low line numbers to higher
numbers.
How to make the words in different
colours? Well this is hard, I mean
really hard, after making the quote
you press control key and the number 3
key. Write the words and close the
quote and do the rest of the line.
Same for the words white, although you
make the quote and then press control
key the number 2 for white.
Of course if you have some experience
with this sort of thing, you may now
want to try to have the number come
out as a different colour. Thing here
is to see that, what ever colour you
last used will be the colour that will
continue to be used, until you change
it. You can change the colour with the
command of pO646,X where X is a colour
from 0-15. Or PRINT"<control and a
number key" Or PRINT"<c= key and
number key". Actually on a programme
line it would look a little like ?" ".
There will be a symbol between the
quotes, call this for now a colour
code. That will print as the colour
for the text. Have fun playing around,
and feel randy and see what you can do
with reverse video.
New programme and type in
10 ?"<CLEAR/HOME>"
20 ? CHR$(205.5)+RND(1))
40 GOTO20
Run that and see what happens on the
screen.
If you have a mess of M and N show up,
press shift and C= for upper case. Ah
there is this weird maze looking thing
that shows up, over and over and over
again. The programme will run until
you press that run/stop key. What is
going on here? That was my question,
all of that stuff on screen for just a
few lines of programming.
We have already understood the first
line as the shifted clear home to
clear the screen.
The Last line is the goto statement
that loops the programme back again.
But all the action is created in line
20. But what is happening there? We
can tell that there is a print
command, we can see that this is going
to print something to do with a sort
of random number generator. A closer
look at the screen shows that the
things printed are the slash lines on
the N and M keys. How doe two symbols
appear with only one statement to
print them? That is how it looks at
first. Lets work things out a bit.
CHR$ stands for "character string",
remember I said that there are 256,
that is from 0-255, characters for the
C=. Well each one of them has a
character string, or a number. Real
simple now, what is happening is that
the chr$(205) is a one symbol. There
is no chr$(205.5) the random number
generator is basically making a number
that will be between 205.5 and 206.5.
chr$ will only accept the whole
number. So you have a 50/50 chance of
each of the two chr$ characters
showing up and being printed on the
screen, Rather fast for a 1mcps speed
machine. <VBG>
CONTINUED IN SECTION 2